<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWyFinaBankLogTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('wy_fina_bank_log', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->comment('用户ID')->nullable();
            $table->dateTime('transaction_time')->comment('交易时间');
            $table->integer('account_id')->index('account_id')->comment('银行账户表的ID')->nullable();
            $table->string('account_idcode', 250)->comment('查询时用的冗余字段】银行账户（微信和支付宝等等是对应平台用户ID）');
            $table->string('account_name', 255)->comment('查询时用的冗余字段】开户姓名')->default(0);
            $table->string('bank_name', 250)->comment('查询时用的冗余字段】银行名称')->default(0);
            $table->decimal('income', 17, 2)->comment('收入')->default(0);
            $table->decimal('outcome', 17, 2)->comment('支出')->default(0);
            $table->decimal('fee', 17, 2)->comment('手续费')->default(0);
            $table->string('note', 50)->comment('备注');
            $table->tinyInteger('transaction_account_type')->comment('交易对手类型：1.机构账户 2.内部个人账户 3.外部银行账户')->nullable();
            $table->integer('transaction_account_id')->comment('【查询时用的冗余字段】账户ID(机构账户表的ID、个人账户ID,银行账户ID)')->nullable();
            $table->integer('transaction_account_brank_id')->comment('查询时用的冗余字段】交易对手银行ID')->nullable();
            $table->integer('transaction_account_idcode')->comment('查询时用的冗余字段】交易对手银行卡号或账户')->nullable();
            $table->string('transaction_account_name', 250)->comment('【查询时用的冗余字段】账户户名（机构名称，个人账户名、银行账户名）');
            $table->integer('operator_user_id')->comment('发起交易员用户ID。0 代表是个人用户自己发起，或者系统自动发起。非0代表管理后台用户发起')->nullable();
            $table->index(['user_id', 'transaction_time']);
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('wy_fina_bank_log');
    }
}
